/**
 * 用于 banner 模块
 */
const Pager = require('../../components/aotoo/core/index')
const lib = Pager.lib
const cd = lib.cd

const adapter = (data) => {
  return data.map(item => {
    return {
      img: {
        src: item.img,
        mode: item.mode || 'widthFix',
        aim: item.aim ? 'onJumpPages?path='+item.aim : ''
      }
    }
  })
}

module.exports = function(params={}) {
  let dft = {
    listClass: 'banner-list'
  }
  let opts = Object.assign({}, dft, params)

  return {
    listClass: opts.listClass,
    itemClass: opts.itemClass,
    type: opts.data.length > 1 ? {
      is: 'swiper',
      'indicator-dots': true,
      'indicator-color': '#eee',
      'indicator-active-color': '#FFD500'
    } : '',
    data: adapter(opts.data),
    itemMethod: {
      onJumpPages(e, params, inst) {
        const $path = params.patn
        wx.navigateTo({
          url: $path
        })
      }
    }
  }
}
